<style type="text/css">
    .demo-upload-list {
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
        margin-right: 4px;
    }

    .demo-upload-list img {
        width: 100%;
        height: 100%;
    }

    .demo-upload-list-cover {
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .6);
    }

    .demo-upload-list:hover .demo-upload-list-cover {
        display: block;
    }

    .demo-upload-list-cover i {
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }

    .selected-search {
        box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }

    .work-day {
        /*border: 1px solid red;*/
    }

    .ivu-date-picker-rel {
        width: 200px !important;
    }

    .flow-block {
        max-height: 100px;
        overflow: auto;
        border-radius: 4px;
        border: 1px solid #f0f0f0;
        padding: 10px 0;
        width: 100px;
        margin-left: 20px;
    }

    .flow-block .flow-item {
        text-align: center;

    }

    .ivu-select-multiple .ivu-tag {
        width: 100px;
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="110" style="width: 50%">
        <Form-item label="适用范围" prop="Forusetype">
            <!--            <i-select v-model="formValidate.Forusetype" placeholder="请选择规则适用范围" style="width:200px">-->
            <!--                <i-option value="1">请假</i-option>-->
            <!--                <i-option value="2">车辆</i-option>-->
            <!--            </i-select>-->
            <RadioGroup v-model="formValidate.Forusetype">
                <Radio label="1">请假</Radio>
                <Radio label="2">车辆</Radio>
            </RadioGroup>
        </Form-item>
        <Form-item label="适用类型" prop="Isworkdayuse">
            <RadioGroup v-model="formValidate.Isworkdayuse">
                <Radio :label="true">工作日适用</Radio>
                <Radio :label="false">非工作日适用</Radio>
            </RadioGroup>
            <!--            <i-select v-model="formValidate.Isworkdayuse" placeholder="请选择规则适用类型" style="width:200px">-->
            <!--                <i-option :value="true">工作日适用</i-option>-->
            <!--                <i-option :value="false">非工作日适用</i-option>-->
            <!--            </i-select>-->
        </Form-item>
        <Form-item label="人员类型" prop="Foruserlevel">
            <i-select v-model="formValidate.Foruserlevel" placeholder="请选择适用人员类型"
                      style="width:200px">
                <template v-for="(item,index) in peopleTypeArr">
                    <i-option :value="item.Id">{{item.Levelname}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item label="起始节点" prop="Minhour">
            <i-input v-model="formValidate.Minhour" style="width: 100px;" type="number" placeholder="请输入起始节点"></i-input>
            <span>( 规则生效的起始时间：小时数 )</span>
        </Form-item>
        <Form-item label="终止节点" prop="Maxhour">
            <i-input v-model="formValidate.Maxhour" style="width: 100px;" type="number" placeholder="请输入终止节点"></i-input>
            <span>( 如果需要设计满足起始节点时间以上都能满足的，请将值指定为999 )</span>
        </Form-item>

        <Form-item label="审核人员" prop="Flow">
            <i-select style="width: 120px" placeholder="选择审批人员类型" multiple filterable
                      @on-change="checkChangeGate">
                <i-option v-for="(item,index) in peopleTypeArr" :value="item.Id">
                    {{ item.Levelname }}
                </i-option>
            </i-select>
            <span>( 从上往下为一级审批,以此类推。)</span>
        </Form-item>

        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button @click="backGoJump()">返回</i-button>
        </Form-item>
    </i-form>
</template>
<script>

    import apiUtil from '../../assets/utils/api_util';
    import selectSearch from '../../components/selectSearch';
    import baseUtil from '../../assets/utils/base-util';

    /*

     * */


    export default {
        data() {
            return {
                formValidate: {
                    // //添加字段
                    // rolename: '',
                    // Peopletypeid: '',
                    // Workdaystarthour: '08',
                    // Workdaystartmin: '00',
                    // Workdayendhour: '22',
                    // Workdayendmin: '00',
                    // Workdayuplevelcheckhour: 4,
                    // Freedaystarthour: '08',
                    // Freedaystartmin: '00',
                    // Freedayendhour: '22',
                    // Freedayendmin: '00',
                    // Freedayuplevelcheckhour: 6,
                    // State: false,
                    // // Isneedbroadcast: false,
                    // Flow: [],
                    Forusetype: '1', //
                    Rulecontent: [], //
                    Isworkdayuse: false, //
                    Minhour: 0, //
                    Maxhour: 0, //
                    Foruserlevel: '', //
                },
                flow: [],
                //时段默认数据
                workDay: ["08:00", "22:00"],
                freeDay: ["08:00", "22:00"],
                ruleValidate: {},
                //人员类型
                peopleTypeArr: []


            }
        },
        mounted: function () {
            this.getPeopleTypeData();
        },

        components: {
            selectSearch
        },
        methods: {
            //backJump
            backGoJump: function () {
                this.$router.back(-1)

            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;

                this.$refs[name].validate((valid) => {
                    console.log('dfdsfsd')
                    that.addData(model);

                })
            },

            //选择人员类型
            checkChangeGate: function (data) {
                this.flow = Array.from(data);
            },
            //获取适用人员类型
            getPeopleTypeData: function () {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GetPeopleTypes, params, function (res) {
                    that.$Loading.finish();
                    that.peopleTypeArr = res.Msg;

                    console.log('res:', res)
                });

            },
            //添加
            addData: function (model) {
                let that = this;
                let para = {};
                let Rulecontent = [];

                // if(model.Isworkdayuse == '请假'){
                //     para.Isworkdayuse =1;
                // }else{
                //     para.Isworkdayuse =2;
                // }
                //
                // if(model.Forusetype == '适用工作日'){
                //     para.Forusetype =true;
                // }else{
                //     para.Forusetype =false;
                // }

                para.Isworkdayuse = model.Isworkdayuse;
                para.Forusetype = model.Forusetype;
                para.Foruserlevel = model.Foruserlevel;
                if (model.Maxhour == 0) {
                    para.Maxhour = 0;
                } else {
                    para.Maxhour = model.Maxhour;
                }
                if (model.Minhour == 0) {
                    para.Minhour = 0
                } else {
                    para.Minhour = model.Minhour;
                }


                that.flow.forEach(function (item, index) {
                    let subItem = {};

                    subItem.Index = (index + 1);
                    subItem.AccountRightId = item;
                    Rulecontent.push(subItem);
                });

                para.Rulecontent = JSON.stringify(Rulecontent);

                let params = that.$qs.stringify(para);

                this.$Loading.start();


                console.log('para:', para)
                apiUtil.post(that, apiUtil.urls.AddRule, params, function (res) {
                    that.$Loading.finish();
                    that.$Notice.open({
                        title: '通知',
                        desc: "规则添加成功 "
                    });
                    baseUtil.handleReset(that,'formValidate')

                });
            },

            uploadList() {
                let that = this;
                this.imageList = that.$refs.upload ? that.$refs.upload.fileList : [];
                console.log('this.imageList:', this.imageList);
            },

        }
    }
</script>
